<template>
    <div class="row">
        <div class="col-4 my-4" v-for="column in columnList" :key="column._id">
            <div class="card h-100 shadow-sm">
                <div class="card-body text-center">
                    <img class="rounded-circle border border-light my-3" :src="column.avatar && column.avatar.url"
                        :alt="column.title" />
                    <h5 class="card-title">{{ column.title }}</h5>
                    <p class="card-text text-sm-start">{{ column.description }}</p>
                    <!-- <router-link :to="{ name: 'ColumnDetail', params: {id: column.id} }" class="btn btn-outline-primary">进入专栏</router-link> -->
                    <router-link :to="`/column/${column._id}`" class="btn btn-outline-primary">进入专栏</router-link>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { PropType, computed } from 'vue';
import { ColumnProps } from '@/types';
import { addColumnAvatar } from '@/utils/FileUtils';

const props = defineProps({
    list: {
        // 类型断言
        type: Array as PropType<ColumnProps[]>,
        required: true
    }
});

// 处理默认图片
const columnList = computed(() => {
    return props.list.map(column => {
        addColumnAvatar(column, 50, 50)
        return column
    })
})

const emit = defineEmits([]);

</script>

<style scoped>
.card-body img {
    width: 50px;
    height: 50px;
}
</style>